home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / lib / init / mount-functions.sh < prev    next >
Encoding:
Text File  |  2012-03-27  |  3.7 KB  |  166 lines

  1. #
  2. # Functions used by several mount* scripts in initscripts package
  3. #
  4. # Sourcer must source /lib/lsb/init-functions.sh
  5.  
  6. # $1: directory
  7. is_empty_dir() {
  8.     for FILE in $1/* $1/.*
  9.     do
  10.         case "$FILE" in
  11.           "$1/.*") return 0 ;;
  12.           "$1/*"|"$1/."|"$1/..") continue ;;
  13.           *) return 1 ;;
  14.         esac
  15.     done
  16.     return 0
  17. }
  18.  
  19.  
  20. selinux_enabled () {
  21.     which selinuxenabled >/dev/null 2>&1 && selinuxenabled
  22. }
  23.  
  24.  
  25. # Called before mtab is writable to mount kernel and device file systems.
  26. # $1: file system type
  27. # $2: alternative file system type (or empty string if none)
  28. # $3: mount point
  29. # $4: mount device name
  30. # $5... : extra mount program options
  31. domount () {
  32.     MTPT="$3"
  33.     KERNEL="$(uname -s)"
  34.     # Figure out filesystem type
  35.     FSTYPE=
  36.     if [ "$1" = proc ]
  37.     then
  38.         case "$KERNEL" in
  39.             Linux|GNU) FSTYPE=proc ;;
  40.             *FreeBSD)  FSTYPE=linprocfs ;;
  41.             *)         FSTYPE=procfs ;;
  42.         esac
  43.     elif [ "$1" = tmpfs ]
  44.     then # always accept tmpfs, to mount /lib/init/rw before /proc
  45.         FSTYPE=$1
  46.     elif grep -E -qs "$1\$" /proc/filesystems
  47.     then
  48.         FSTYPE=$1
  49.     elif grep -E -qs "$2\$" /proc/filesystems
  50.     then
  51.         FSTYPE=$2
  52.     fi
  53.  
  54.     if [ ! "$FSTYPE" ]
  55.     then
  56.         if [ "$2" ]
  57.         then
  58.             log_warning_msg "Filesystem types '$1' and '$2' are not supported. Skipping mount."
  59.         else
  60.             log_warning_msg "Filesystem type '$1' is not supported. Skipping mount."
  61.         fi
  62.         return
  63.     fi
  64.  
  65.     # We give file system type as device name if not specified as
  66.     # an argument
  67.     if [ "$4" ] ; then
  68.         DEVNAME=$4
  69.     else
  70.         DEVNAME=$FSTYPE
  71.     fi
  72.  
  73.     # Get the options from /etc/fstab.
  74.     OPTS=
  75.     if [ -f /etc/fstab ]
  76.     then
  77.         exec 9<&0 </etc/fstab
  78.  
  79.         while read TAB_DEV TAB_MTPT TAB_FSTYPE TAB_OPTS TAB_REST
  80.         do
  81.             case "$TAB_DEV" in (""|\#*) continue ;; esac
  82.             [ "$MTPT" = "$TAB_MTPT" ] || continue
  83.             [ "$FSTYPE" = "$TAB_FSTYPE" ] || continue
  84.             case "$TAB_OPTS" in
  85.               noauto|*,noauto|noauto,*|*,noauto,*)
  86.                 exec 0<&9 9<&-
  87.                 return
  88.                 ;;
  89.               ?*)
  90.                 OPTS="-o$TAB_OPTS"
  91.                 ;;
  92.             esac
  93.             break
  94.         done
  95.  
  96.         exec 0<&9 9<&-
  97.     fi
  98.  
  99.     if [ ! -d "$MTPT" ]
  100.     then
  101.         log_warning_msg "Mount point '$MTPT' does not exist. Skipping mount."
  102.         return
  103.     fi
  104.  
  105.     if mountpoint -q "$MTPT"
  106.     then
  107.         return # Already mounted
  108.     fi
  109.  
  110.     if [ "$VERBOSE" != "no" ]; then
  111.         is_empty_dir "$MTPT" >/dev/null 2>&1 || log_warning_msg "Files under mount point '$MTPT' will be hidden."
  112.     fi
  113.     mount -n -t $FSTYPE $5 $OPTS $DEVNAME $MTPT
  114.     if [ "$FSTYPE" = "tmpfs" -a -x /sbin/restorecon ]; then
  115.         /sbin/restorecon $MTPT
  116.     fi
  117. }
  118.  
  119. #
  120. # Preserve /var/run and /var/lock mountpoints
  121. #
  122. pre_mountall ()
  123. {
  124.     # We may end up mounting something over top of /var, either directly
  125.     # or because /var is a symlink to something that's mounted.  So keep
  126.     # copies of the /var/run and /var/lock mounts elsewhere on the root
  127.     # filesystem so they can be moved back.
  128.     if [ yes = "$RAMRUN" ] ; then
  129.         mkdir /lib/init/rw/var.run
  130.         mount -n --bind /var/run /lib/init/rw/var.run
  131.     fi
  132.     if [ yes = "$RAMLOCK" ] ; then
  133.         mkdir /lib/init/rw/var.lock
  134.         mount -n --bind /var/lock /lib/init/rw/var.lock
  135.     fi
  136. }
  137.  
  138. #
  139. # Restore /var/run and /var/lock mountpoints if something was mounted
  140. # as /var/.  Avoid mounting them back over themselves if nothing was
  141. # mounted as /var/ by checking if /var/run/ and /var/lock/ are still
  142. # mount points.  Enabling RAMRUN and RAMLOCK while listing /var/run or
  143. # /var/lock in /etc/fstab is not supported.
  144. #
  145. post_mountall ()
  146. {
  147.     if [ yes = "$RAMRUN" ] ; then
  148.         [ -d /var/run ] || mkdir /var/run
  149.         if mountpoint -q /var/run ; then
  150.             umount /lib/init/rw/var.run
  151.         else
  152.             mount -n --move /lib/init/rw/var.run /var/run
  153.         fi
  154.         rmdir /lib/init/rw/var.run
  155.     fi
  156.     if [ yes = "$RAMLOCK" ] ; then
  157.         [ -d /var/lock ] || mkdir /var/lock
  158.         if mountpoint -q /var/lock ; then
  159.             umount /lib/init/rw/var.lock
  160.         else
  161.             mount -n --move /lib/init/rw/var.lock /var/lock
  162.         fi
  163.         rmdir /lib/init/rw/var.lock
  164.     fi
  165. }
  166.